package com.soft.service;

import com.soft.dao.ProductsDAO;
import com.soft.pojo.Products;

import java.util.ArrayList;
import java.util.List;

public class ProductsService {

    public ProductsDAO productsdao = new ProductsDAO();

    public ArrayList<Products> showProducts(int currentPage, int currentCount, String category) {
        return (ArrayList<Products>) productsdao.selectAll(currentPage, currentCount, category);
    }

    public ArrayList<Products> findProducts() {
        return (ArrayList<Products>) productsdao.selectAll();
    }

    public int productCount(String category) {
        List<Products> productsList = productsdao.selectProductCount(category);
        return productsList.size();
    }

    public void addProducts(Products products) {
        productsdao.insertProducts(products);
    }

    public void delProducts(String id) {
        productsdao.delProductsById(id);
    }

    public ArrayList<Products> findProductByManyCondition(String id, String name, String category, double minprice, double maxprice) {
        return (ArrayList<Products>) productsdao.selectProductByManyCondition(id, name, category, minprice, maxprice);
    }

    public Products findProductsByID(String id) {
        return productsdao.findProductsById(id);
    }

    public void editProducts(Products products) {
        productsdao.updateProducts(products);
    }
}
